package com.kedacom.general.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.kubernetes.config.event.ConfigMapEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.MapPropertySource;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author WangQiang
 * @date 2018-03-19 17:05
 * 监听配置信息
 **/
@Slf4j
@Component
public class ConfigMapEventListener implements ApplicationListener<ConfigMapEvent> {
    // 以前配置信息
    public static MapPropertySource CONFIG_CURRENTMAP;
    // 最新的配置信息
    public static MapPropertySource CONFIG_PREVIOUSMAP;
    // 变化的配置信息
    public static Map<String, Map> CONFIG_CHANGES;
    @Override
    public void onApplicationEvent(ConfigMapEvent configMapEvent) {
        MapPropertySource currentMap = configMapEvent.getCurrentMap();
        CONFIG_CURRENTMAP=currentMap;
        MapPropertySource previousMap = configMapEvent.getPreviousMap();
        CONFIG_PREVIOUSMAP=previousMap;
        Map<String, Map> configChanges = configMapEvent.getConfigChanges();
        CONFIG_CHANGES=configChanges;
    }
}
